/**
 * @author:linjiye
 * @date: 2024/01/13
 * @desc: 用于全局接口请求自定义控制字段
 **/

import useGetStorage from "@/hooks/useGetStorage";
import SSE from "@/utils/custom/see";

let token = null
useGetStorage('token').then(res => {
    token = res
})

const useApiOfSSE = ({url, headers, payload, method = 'post'}) => {
    const baseUrl = process.env.EXPO_PUBLIC_API_URL + url
    // const baseUrl = 'http://192.168.10.122:8080/' + url
    let token = useGetStorage('token')
    return new SSE(baseUrl, {
        headers: {
            'Content-Type': 'application/json',
            'X-Access-Token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDA1NzgxMzksInVzZXJuYW1lIjoieWl6dW9taW4ifQ.GSwIxpSqHd-Li2vS7aQ3WG48m7xxy_mGzgkZB2tLa64',
            ...headers
        },
        payload: JSON.stringify(payload),
        method
    })
}

export default useApiOfSSE